<template>
  <!-- 内容 -->
  <slot name="leftContent" :thumbUrl="props.infoData.thumbnailUrl"></slot>
  <div class="content">
    <div class="div-title">
      <!-- 类型 -->
      <i :class="typeIcon" class="inco-color" :style="typeIconStyle"></i>
      <!-- 标题 -->
      <div :title="props.infoData.infoName" class="title">
        {{ props.infoData.infoName }}
      </div>
      <!--状态 -->
      <span v-if="props.isDraft === 0" class="state" :style="state.style">{{ state.title }}</span>
    </div>
    <!-- 发布内容 -->
    <div class="content-text" :title="removeHtmlTags(props.infoData.infoDesc)">
      {{ removeHtmlTags(props.infoData.infoDesc) }}
    </div>
    <div class="name">
      <!-- 发布人 -->
      <span>{{ props.infoData.releaseUserName }}</span>
      <span v-if="props.isDraft === 0" class="time">
        {{ getFormattedPublishTime(props.infoData.createTime) }}
      </span>
      <span v-else class="time">{{ getFormattedPublishTime(props.infoData.updateTime) }}</span>
    </div>
  </div>
</template>
<script setup>
import { computed, defineProps, onMounted, ref, watch } from 'vue';
import { getFormattedPublishTime } from '@/util/formatDate';
import { defaultFengmian, getEscapeUrl } from '@/util/OBSUpload';
import { removeHtmlTags } from '@/util/utils';

onMounted(() => {});
const props = defineProps({
  infoData: { type: Object },
  isDraft: { type: Number, default: 0 }
});
// 类型图标
const typeIcon = computed(() => {
  switch (props.infoData.infoType) {
    case 0:
      return 'ifont-wid-leftbar_icon_video_default';
    case 1:
      return 'ifont-wid-leftbar_icon_image_default';
    case 2:
      return 'ifont-wid-leftbar_icon_documentation_default';
    case 3:
      return 'ifont-wid-leftbar_icon_article_default';
    default:
      return 'ifont-wid-leftbar_icon_article_default';
  }
});

// 图标样式
const typeIconStyle = ref({
  marginRight: '8px',
  fontSize: '18px',
  verticalAlign: 'top'
});

// 状态显示
// 状态显示
const state = computed(() => {
  if (props.infoData.infoState === 1) {
    return {
      title: '已发布',
      style: {
        color: '#56D6B7',
        background: 'rgba(86,214,183,0.16)'
      }
    };
  } else if (props.infoData.infoState === 4) {
    return {
      title: '已撤回',
      style: {
        color: '#FE8F8F',
        background: 'rgba(254,143,143,0.16)'
      }
    };
  } else if (props.infoData.infoState === 3) {
    return {
      title: '已结束',
      style: {
        color: '#999999',
        background: 'rgba(153,153,153,0.16)'
      }
    };
  } else {
    return {
      title: '待生效',
      style: {
        color: '#FE8F8F',
        background: 'rgba(254,143,143,0.16)'
      }
    };
  }
});
</script>
<style lang="less" scoped>
.content {
  margin-left: 16px;
  height: 120px;
  width: 100%;
  overflow: hidden;
  .div-title {
    height: 24px;
    line-height: 24px;
    display: flex;
    .title {
      color: #222222;
      font-size: 16px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .state {
      background-color: #f2f2f2;
      color: #999999;
      font-size: 12px;
      width: 52px;
      height: 24px;
      border-radius: 2px;
      text-align: center;
      margin-left: 8px;
      padding: 0px;
      flex-shrink: 0;
      margin-right: 20px;
    }
  }
  .name {
    height: 24px;
    color: #999999;
    font-size: 14px;
    margin-top: 16px;
    .time {
      margin-left: 13px;
    }
  }
  .content-text {
    // max-width: 700px;
    width: 342px;
    overflow: hidden;
    white-space: normal;
    /*文字超出宽度则显示ellipsis省略号*/
    margin-top: 14px;
    height: 45px;
    font-size: 14px;

    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;

    color: #999999;
    word-break: break-all;
  }
}
.inco-color {
  color: #d6aa56;
}
.content {
  // display: flex;
  // justify-content: space-between;
}
</style>
